package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.TypeOfCompetitionDetails;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.TypeOfCompetitionDetailsService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 typeOfCompetitionDetailsController
//@RequestMapping("/typeOfCompetitionDetailsController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /typeOfCompetitionDetailsController
public class TypeOfCompetitionDetailsController {
	@Resource
    TypeOfCompetitionDetailsService typeOfCompetitionDetailsService;

	@GetMapping("/typeOfCompetitionDetailss")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<TypeOfCompetitionDetails> getAllTypeOfCompetitionDetails() throws Exception{
    	System.out.println("查询全部专家");
    	return typeOfCompetitionDetailsService.getAllTypeOfCompetitionDetailss();
    }

	@PostMapping("/typeOfCompetitionDetails")
	@ResponseBody
	public DTO<TypeOfCompetitionDetails> addTypeOfCompetitionDetails(@RequestBody TypeOfCompetitionDetails typeOfCompetitionDetails) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加专家成功");
		return typeOfCompetitionDetailsService.addTypeOfCompetitionDetails(typeOfCompetitionDetails);
	}
	@DeleteMapping("/typeOfCompetitionDetails/{tocdno}")
	@ResponseBody
    public DTO<TypeOfCompetitionDetails> deleteTypeOfCompetitionDetailsByTocdno(@RequestBody @PathVariable("tocdno") String tocdno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(tocdno+"删除专家成功");
    	return typeOfCompetitionDetailsService.deleteTypeOfCompetitionDetailsByTocdno(tocdno);
    }

	@GetMapping("/typeOfCompetitionDetails/{tocdno}")
	@ResponseBody
	public DTO<TypeOfCompetitionDetails> getTypeOfCompetitionDetailsByTocdno(@PathVariable("tocdno") String tocdno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(tocdno+"根据主键查询专家成功");
		return typeOfCompetitionDetailsService.getTypeOfCompetitionDetailsByTocdno(tocdno);
	}

	@PatchMapping("/typeOfCompetitionDetails")
	@ResponseBody
	public DTO<TypeOfCompetitionDetails> updateTypeOfCompetitionDetailsByTocdno(@RequestBody TypeOfCompetitionDetails typeOfCompetitionDetails) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改专家成功");
		System.out.println(typeOfCompetitionDetails);
		return typeOfCompetitionDetailsService.updateTypeOfCompetitionDetailsByTocdno(typeOfCompetitionDetails);
	}

	@RequestMapping("/typeOfCompetitionDetailss/pageInfo")
	@ResponseBody
	public DTO<TypeOfCompetitionDetails> getTypeOfCompetitionDetailsByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return typeOfCompetitionDetailsService.getTypeOfCompetitionDetailsByPage(pageInfo);
	}

}
